package com.rayc.mall.logistic.controller;

import com.rayc.mall.api.dto.OrderDTO;
import com.rayc.mall.common.constant.Constants;
import com.rayc.mall.common.result.Result;
import com.rayc.mall.core.annotation.CacheAddByUserId;
import com.rayc.mall.logistic.domain.vo.OrderLogisticsVO;
import com.rayc.mall.logistic.service.IOrderLogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Ray-C
 * @CreateTime: 2025-03-25
 * @Description: 物流管理相关接口
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "物流管理接口")
@RestController
@RequestMapping("/logistics")
@RequiredArgsConstructor
public class LogisticsController {
    private final IOrderLogisticsService orderLogisticsService;

    @ApiOperation("获取物流信息")
    @GetMapping("/list")
    @CacheAddByUserId(key = Constants.REDIS_KEY_LOGISTICS)
    public Result<List<OrderLogisticsVO>> queryMyLogistics() {
        log.info("查询物流信息列表");
        List<OrderLogisticsVO> logisticsList = orderLogisticsService.queryMyLogistics();
        log.info("查询物流信息列表成功 {}", logisticsList);
        return Result.success(logisticsList);
    }

    // feign interface
    @PostMapping("/create")
    public Result<String> createLogistics(OrderDTO order) {
        log.info("创建订单物流, 订单信息: {}", order);
        orderLogisticsService.createLogistics(order);
        log.info("创建订单物流成功, 订单信息: {}", order);
        return Result.success();
    }
}
